package org.gis.utils.dps;

import java.beans.PropertyDescriptor;
import java.io.Serializable;


/**
 *
 * @author gus
 */
public class DynamicProperty implements Serializable
{
    protected final static long serialVersionUID = -1253413589L;
    private DynamicPropertySet parent;
    
    protected transient PropertyDescriptor descriptor;
    protected Class type;
    protected Object value;

    public DynamicProperty( String name, Class type ) throws Exception
    {
        this( new PropertyDescriptor( name, null, null ), type, null );
    }

    public DynamicProperty( PropertyDescriptor descriptor, Class type )
    {
        this( descriptor, type, null );
    }

    public DynamicProperty( String name, Class type, Object value ) throws Exception
    {
        this( new PropertyDescriptor( name, null, null ), type, value );
    }

    public DynamicProperty( String name, String displayName, Class type )  throws Exception
    {
        this( name, displayName, null, type, null );
    }

    public DynamicProperty( String name, String displayName, String shortDesc, Class type ) throws Exception
    {
        this( name, displayName, shortDesc, type, null );
    }

    public DynamicProperty( String name, String displayName, Class type, Object value ) throws Exception
    {
        this( name, displayName, null, type, value );
    }

    public DynamicProperty( String name, String displayName, String shortDesc, Class type, Object value ) throws Exception
    {
        this( name, type, value );
        descriptor.setDisplayName( displayName );
        descriptor.setShortDescription( shortDesc );
    }

    public DynamicProperty( PropertyDescriptor descriptor, Class type, Object value )
    {
        this.descriptor = descriptor;
        this.type = type;
        this.value = value;
    }

    public PropertyDescriptor getDescriptor()
    {
        return descriptor;
    }


    public String getName()
    {
        return descriptor.getName();
    }

    public void setName( String name )
    {
        descriptor.setName( name );
    }

    public String getDisplayName()
    {
        return descriptor.getDisplayName();
    }

    public void setDisplayName( String name )
    {
        descriptor.setDisplayName( name );
    }

    public String getShortDescription()
    {
        return descriptor.getShortDescription();
    }

    public void setShortDescription( String shortDesc )
    {
        descriptor.setShortDescription( shortDesc );
    }

    public Class getType()
    {
        return type;
    }

    public void setType( Class type )
    {
        this.type = type;
    }

    public Object getValue()
    {
        return value;
    }

    public void setValue( Object value )
    {
        Object oldValue = this.value;
        this.value = value;
        if( parent != null )
        {
            parent.firePropertyChange( descriptor.getName(), oldValue, value );
        }
    }

    public Object getAttribute( String attrName )
    {
        return descriptor.getValue( attrName );
    }

    public void setAttribute( String attrName, Object attrValue )
    {
        descriptor.setValue( attrName, attrValue );
    }

    public boolean isHidden()
    {
        return descriptor.isHidden();
    }

    public void setHidden( boolean hidden )
    {
        descriptor.setHidden( hidden );
    }

    public boolean isExpert()
    {
        return descriptor.isExpert();
    }

    public void setExpert( boolean expert )
    {
        descriptor.setExpert( expert );
    }

    public DynamicPropertySet getParent()
    {
        return parent;
    }

    public void setParent( DynamicPropertySet parent )
    {
        this.parent = parent;
    }
}


